impl Solution {
    pub fn two_city_sched_cost(costs: Vec<Vec<i32>>) -> i32 {
        let mut dif=Vec::<(i32,usize)>::with_capacity(costs.len());
        for (i,v) in costs.iter().enumerate(){
            dif.push((v[0]-v[1],i));
        };
        dif.sort_by_key(|item|item.0.abs());
        let (mut num1,mut num2)=(costs.len()/2,costs.len()/2);
        let mut ans=0;
        for &item in dif.iter().rev(){
            if item.0<0{
                if num1>0{
                    ans+=costs[item.1][0];
                    num1-=1;
                }else{
                    ans+=costs[item.1][1];
                    num2-=1;
                }  
            }else{
                if num2>0{
                    ans+=costs[item.1][1];
                    num2-=1;
                }else{
                    ans+=costs[item.1][0];
                    num1-=1;
                }
            }
        };
        ans
    }
}